#include "deque.h"

int deque_init(TDeQueue* que,int max_size)
{
	que->max_size = max_size;
	que->read = que->write = que->size = 0;
	
	return max_size;
}
int deque_push(TDeQueue* que)
{
	int next_pos = ((que->write+1)%que->max_size);
	int prev_pos  = que->write;
	if(next_pos == que->read){
		que->read = (que->read+1)%que->max_size;
	}		
	que->write = next_pos;
	que->size++;
	
	return prev_pos;
}

int deque_front(TDeQueue* que)
{
	if(que->read != que->write)
		return que->read;
	else 
		return DEQUE_NONE_POS;
}

void deque_pop(TDeQueue* que)
{
	
	if(que->read != que->write){
		que->read = (que->read+1)%que->max_size;
		if(que->size > 0)
			que->size--;		
	} 
}
int  deque_size(TDeQueue* que)
{
	return que->size;
}

